import request from '@/api/request'
import { AxiosPromise } from 'axios'
import { CommentQuery, CommentPageResult, CommentVO } from './types'

/**
 * 评论分页列表
 *
 * @param queryParams
 */
export function pageComment(queryParams: CommentQuery): AxiosPromise<CommentPageResult> {
  return request({
    url: '/api/v1/comment/page',
    method: 'get',
    params: queryParams,
  })
}

/**
 * 回复评论分页列表
 *
 * @param queryParams
 */
export function pageReply(queryParams: CommentQuery): AxiosPromise<CommentPageResult> {
  return request({
    url: '/api/v1/comment/replyPage',
    method: 'get',
    params: queryParams,
  })
}

/**
 * 评论表单数据
 *
 * @param id
 */
export function getCommentById(id: number): AxiosPromise<CommentVO> {
  return request({
    url: '/api/v1/comment/' + id,
    method: 'get',
  })
}

/**
 * 新增评论
 *
 * @param data
 */
export function saveComment(data: CommentVO) {
  return request({
    url: '/api/v1/comment',
    method: 'post',
    data: data,
  })
}

/**
 * 修改评论
 *
 * @param data
 */
export function updateComment(data: CommentVO) {
  return request({
    url: '/api/v1/comment/' + data.id,
    method: 'put',
    data: data,
  })
}

/**
 * 启用/禁用评论
 *
 * @param data
 */
export function updateCommentEnabled(data: CommentVO) {
  return request({
    url: '/api/v1/comment/enabled',
    method: 'put',
    data: data,
  })
}

/**
 * 删除评论
 */
export function deleteComment(ids: Number[]) {
  return request({
    url: '/api/v1/comment',
    method: 'delete',
    data: ids,
  })
}

/**
 * 下载评论导入模板
 *
 * @returns
 */
export function downloadTemplateApi() {
  return request({
    url: '/api/v1/comment/template',
    method: 'get',
    responseType: 'arraybuffer',
  })
}

/**
 * 导入评论
 *
 * @param file
 */
export function importComment(deptId: number, file: File) {
  const formData = new FormData()
  formData.append('file', file)
  return request({
    url: '/api/v1/comment/_import',
    method: 'post',
    params: { deptId: deptId },
    data: formData,
    headers: { 'Content-Type': 'multipart/form-data' },
  })
}

/**
 * 导出评论
 *
 * @param queryParams
 * @returns
 */
export function exportComment(queryParams: CommentQuery) {
  return request({
    url: '/api/v1/comment/export',
    method: 'get',
    params: queryParams,
    responseType: 'arraybuffer',
  })
}
